﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_IDAL;
using Zor_Tools;

namespace Zor_DAL
{
    public class GIS_AnnualTask_DAL<T> where T : class
    {
        /// <summary>
        /// 获取导出部分列表数据
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static List<T> SelectAnnualTaskTable(string where = null)
        {
            string strwhere = "";
            if (!string.IsNullOrEmpty(where))
            {
                strwhere = "1=1 " + where;
            }
            else
            {
                strwhere = "1=1 ";
            }
            var sql = "select * from [dbo].[V_GIS_AnnualTask] where " + strwhere + "";
            return DapperQuery<T>.DoQueryList(sql, null);
        }

        
        /// <summary>
        /// 年度任务完成表 获取页面数据
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static List<T> GetGIS_AnnualTask(string where)
        {
            var sqlStr = string.Empty;
            if (where == null || where == "")
            {
                //获取当前的年份
                var nowYear = TimeHelper.ToTimeStamp(DateTime.Parse((DateTime.Now.Year + "-01" + "-01").ToString()));
                //获取下一年的年份
                var nextYear = TimeHelper.ToTimeStamp(DateTime.Parse(((DateTime.Now.Year + 1) + "-01" + "-01").ToString()));

                sqlStr = "select StreetOffice,AtRegisteredPlan,AtRevenuePlan,SUM(ANumber) as ANumber ,SUM(PNumber) as PNumber,StreetOfficeShopNumber,StreetOfficeHousNumber,SUM(xiaoji) as xiaoji from [V_GIS_AnnualTask] where   Pt_Date>=" + nowYear + " and Pt_Date<" + nextYear + " group by StreetOffice,AtRegisteredPlan,AtRevenuePlan,StreetOfficeShopNumber,StreetOfficeHousNumber";
            }
            else
            {
                //查询年份
                var nowYear = TimeHelper.ToTimeStamp(DateTime.Parse(where + "-01" + "-01"));
                var nextYear = TimeHelper.ToTimeStamp(DateTime.Parse((int.Parse(where) + 1) + "-01" + "-01"));
                sqlStr = "select StreetOffice,AtRegisteredPlan,AtRevenuePlan,SUM(ANumber) as ANumber ,SUM(PNumber) as PNumber,StreetOfficeShopNumber,StreetOfficeHousNumber,SUM(xiaoji) as xiaoji from [V_GIS_AnnualTask] where   Pt_Date>=" + nowYear + " and Pt_Date<" + nextYear + " group by StreetOffice,AtRegisteredPlan,AtRevenuePlan,StreetOfficeShopNumber,StreetOfficeHousNumber";
            }
            return DapperQuery<T>.DoQueryList(sqlStr, null);
        }
    }
}
